package everydayGrade.t3;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;

/**
 * @Author: Siantar
 * @Date: 2023-07-18-21:54
 * @Description: 1.0
 */
public class T0659 {
    public boolean isPossible(int[] nums) {
        Map<Integer, PriorityQueue<Integer>> map = new HashMap<>();
        for (int num : nums) {
            if (!map.containsKey(num)) {
                map.put(num, new PriorityQueue<Integer>());
            }
            if (map.containsKey(num - 1)) {
                if (!map.get(num - 1).isEmpty()) {
                    map.get(num).offer((int) map.get(num - 1).poll() + 1);
                    continue;
                }
            }
            map.get(num).offer(1);
        }
        for (Map.Entry<Integer,PriorityQueue<Integer>>  entry: map.entrySet()) {
            if (entry.getValue().peek() < 3) return false;
        }
        return true;
    }
}
